package com.rent.view;

import java.util.Scanner;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Scanner;
import com.rent.bean.Rent;
import com.rent.bean.User;
import com.rent.bean.Vip;
import com.rent.dao.RecordDao;
import com.rent.dao.VipDao;
import com.rent.Impl.RecordImpl;
import com.rent.Impl.VipDaoImpl;
import com.rent.utils.ViewUtils;
/**
 * 普通用户
 * @author xin
 *
 */
public class OrdinaryMenu {
	Scanner input=new Scanner(System.in);
	ViewUtils v = new ViewUtils();
	Scanner sn = new Scanner(System.in);
	Option o = new Option();
	RecordDao re=new RecordImpl();
	VipDao vip1=new VipDaoImpl();
	/**
	 * 普通用户界面
	 */
	
	public void menu_ordinary(User u) {
		l:do {
			System.out.println("***********神州租车系统***********当前用户:" + u.getUname() + "----用户级别：普通用户");
			System.out.println("请选择业务： 1、租车/还车 2、查询记录  3、充值会员 4.充值余额 0.退出");
			switch (sn.nextInt()) {
			case 0:
				System.out.println("系统退出");
				break l;
			case 1:
				o.leaseOrReturn(u);
				continue;
			case 2:
				o.show_rent(u);
				continue;
			case 3:
				czhi(u);
				continue;
			case 4:
				jine(u);
				continue;
			default:
				System.out.println("输入不合法");
				continue;
			}
		} while (true);
	}
	public void pcha(User u) {
		List<Rent> li=re.selectw(u.getUname());
		System.out.println("编号\t用户名\t车辆编号\t租车时间\t\t\t还车时间\t\t\t费用");
		for(Rent r:li) {
			System.out.println(r.getRid()+"\t"+r.getUname()+"\t "+r.getCid()+"\t"+r.getRtime()+"\t"+r.getBtime()+"\t"+r.getMoney());
		}
	}
	public void czhi(User us) {
		System.out.println("国庆特惠！会员月卡300元！年卡只需2500元");
		System.out.println("现在充值会员，享租车九折优惠，更有大量会员专属座驾！");
		System.out.println("请选择:(1.充值月卡(30天));2.充值年卡(365天);3.我在想想");
		int chong=input.nextInt();
		switch(chong) {
		case 1:
			chong(us);
			break;
		case 2:
			chong1(us);
			break;
		case 3:
			menu_ordinary(us);
			break;
		default:
			System.out.println("输入的不合法");
			break;
		}
	}
	//充值30天
	public void chong(User us) {
		int gg=re.gengxin(us.getUname());
		if(gg!=0) {
		Date date=new Date();
		SimpleDateFormat simp=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Calendar ca = Calendar.getInstance();
		re.getVip(us.getUname());
		String opentime=simp.format(date);
		ca.add(Calendar.DATE, 30);//月卡加三十天
		date=ca.getTime();
		String limittime=simp.format(date);
		Vip vip=new Vip(0,us.getUname(),opentime,limittime);
		vip1.newVip(us, vip);
			System.out.println("年卡充值成功！恭喜您已成为神州会员！会员有效期至："+limittime);
			System.out.println("请重新登录:");
			Menu men=new Menu();
			men.init();
		}else {
			System.out.println("您的余额不足");
		}
		
	}
	public void chong1(User us) {
		int gg=re.gengx(us.getUname());
		if(gg!=0) {
		Date date=new Date();
		SimpleDateFormat simp=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Calendar ca = Calendar.getInstance();
		re.getVip(us.getUname());
		String opentime=simp.format(date);
		ca.add(Calendar.DATE, 365);//月卡加三十天
		date=ca.getTime();
		String limittime=simp.format(date);
		Vip vip=new Vip(0,us.getUname(),opentime,limittime);
		vip1.newVip(us, vip);
		System.out.println("年卡充值成功！恭喜您已成为神州会员！会员有效期至："+limittime);
		System.out.println("请重新登录:");
		String deng=input.next();
		Menu men=new Menu();
		men.init();
		}else {
			System.out.println("您的余额不足");
		}
	}
	public void jine(User u) {
		User us=new User();
		us.setUname(u.getUname());
		System.out.println("请输入充值金额:");
		us.setMoney(input.nextDouble());
		
		int chong=vip1.topup(us);
		if(chong==0) {
			System.out.println("充值成功");
			User us1=re.yuer(u.getUname());
			System.out.print("您的账户余额为:");
			System.out.println(us1.getMoney());
		}
	}
}
